package top.tsyz.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.tsyz.entity.Category;
import top.tsyz.service.ICategoryService;

import java.util.List;

/**
 * CategoryController控制器
 */
@RestController
@RequestMapping("/api/categories")
@Api(tags = "Category管理接口")
public class CategoryController {

    @Autowired
    private ICategoryService icategoryservice;

    @GetMapping("/list")
    @ApiOperation("获取所有Category")
    public List<Category> list() {
        return icategoryservice.list();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据ID获取Category")
    public Category getById(@PathVariable Long id) {
        return icategoryservice.getById(id);
    }

    @PostMapping
    @ApiOperation("新增Category")
    public boolean save(@RequestBody Category category) {
        return icategoryservice.save(category);
    }

    @PutMapping
    @ApiOperation("更新Category")
    public boolean update(@RequestBody Category category) {
        return icategoryservice.updateById(category);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除Category")
    public boolean delete(@PathVariable Long id) {
        return icategoryservice.removeById(id);
    }
}
